#include <compat/memory.h>

void* heap_malloc(size_t size)
{
	void *p = malloc(size);
	return p;
}
void heap_free(void *ptr)
{
	free(ptr);
}
void* heap_calloc(size_t n, size_t size)
{
	void* ptr = heap_malloc(n* size);
	return ptr;
}
void* heap_realloc(void *mem_address, size_t size)
{
	void* ptr = realloc(mem_address,size);
	return ptr;
}

char* heap_strdup(const char *str)
{
	char *sdup;
	size_t len = strlen(str) + 1;

	sdup = (char *)heap_malloc(len);
	if (sdup == NULL)
		return NULL;
	memcpy(sdup, str, len);

	return sdup;
}
void* os_memrchr(const void *s, int c, size_t n) 
{
	if (n > 0) {
		const unsigned char *p = s;
		const unsigned char *q = s;

		p += n - 1;

		while (p >= q) {
			if (*p == (unsigned char)c)
				return (void *)p;
			p--;
		}
	}
	return NULL;
}